package com.zjw.dao.impl;

import com.zjw.dao.BaseDao;
import com.zjw.dao.GradeDao;
import com.zjw.entity.Grade;
import com.zjw.utils.ConnectionUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @projectName: studentCourseSelectionManagement
 * @package: com.zjw.dao.impl
 * @className: GradeDaoImpl
 * @author: 翟
 * @date: 2025/4/6 21:04
 */

public class GradeDaoImpl extends BaseDao implements GradeDao {

    public GradeDaoImpl(Connection connection) {
        super(connection);
    }

    @Override
    public List<Grade> selectAllGrade() throws SQLException {
        List<Grade> list = new ArrayList<>();
        ResultSet resultSet = null;
        try {
            resultSet = executeQuery("select * from grade");
            while (resultSet.next()){
                Grade grade = new Grade();
                grade.setGradeId(resultSet.getInt("gradeId"));
                grade.setGradeName(resultSet.getString("gradeName"));
                list.add(grade);
            }
            return list;
        } finally {
            ConnectionUtil.closeALL(resultSet , null , null);
        }
    }
}
